﻿using Microsoft.Extensions.Options;
using MySqlConnector;
using NCD.ORMDbContext.Enums;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NCD.ORMDbContext.Dapper
{
    public class ProjectDapperContext : DapperDBContext
    {
        public ProjectDapperContext(IOptions<DapperDBContextOptions> optionsAccessor) : base(optionsAccessor)
        {
        }

        /// <summary>
        /// 重写Dapper连接，指定连接的数据库类型
        /// </summary>
        /// <param name="connectionString"></param>
        /// <returns></returns>
        protected override IDbConnection CreateConnection(string connectionString, DbTypeNameEnum dbType)
        {
            if (dbType == DbTypeNameEnum.MsSql)
            {
                //MsSQL连接
                IDbConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);
                return conn;

            }
            else
            {
                //MySQL连接
                IDbConnection conn = new MySqlConnection(connectionString);
                return conn;
            }
        }
    }
}
